package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.GraphService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xiaomi
 * @date: 2021/10/8
 * @description:
 */
@RestController
@RequestMapping("simple/graph")
@Api(tags = "表示一张有向权重图：使用散列")
@Slf4j
public class SimpleGraphController {

    @Autowired
    GraphService graphService;

    @GetMapping("/addEdge/{start}/{end}/{weight}")
    @ApiOperation("增加一条边")
    public boolean addEdge(@PathVariable("start") String start, @PathVariable("end") String end, @PathVariable("weight") int weight) {
        boolean b = graphService.addEdge(start, end, weight);
        return b;
    }


    @GetMapping("/getWeight/{start}/{end}")
    @ApiOperation("获取边的权重")
    public Integer getWeight(@PathVariable("start") String start, @PathVariable("end") String end) {
        Integer weight = graphService.getWeight(start, end);
        return weight;
    }

}
